require(["dijit/form/MultiSelect", "dijit/form/Button", "dijit/form/ContentPane", "dojo/dom", "dojo/json", "dojo/request", "dojo/_base/window",
	"dojo/_base/declare", "dojo/parser", "dijit/_WidgetBase", "dijit_TemplatedMixin", "dijit/registry"], function(MultiSelect, Button, 
		ContentPane, dom, JSON, request, win, declare, parser, _WidgetBase, _TemplatedMixin, registry){
		
		declare("ListOperations", [_WidgetBase, _TemplateMixin], {
			templateString:
				"<div class='listoperations'>" +
					"<button data-dojo-attach-event='onclick: createOperation'>Create Operation</button>" +
					"<button data-dojo-attach-event='onclick: removeOperation'>Remove Operation</button>" +
					"<select data-dojo-type='dijit/form/MultiSelect' id='operations' name='opertions'></select>" +
				"</div>",
			
			createOperation: function(){
			
			}
			
			removeOperation: function(){
				registry.byId("operations").getSelected.foreach(function(n){
					request.post("operations", {
						data: JSON.stringify({opType: "remove", value:n.value}),
						handleAs: "json"}).then(function(data){
							data = JSON.parse(data);
							if (data == "Successful") {
								tables.destroy(n);
							}
						});
					);
				}
			}
		});
		
		ready(function() {
			
			parser.parse();
			request.post("tables", {
				data: JSON.stringify({opType: "database"}),
				handleAs: "json"}).then(function(data){
					var attr = dom.byId('tables');
					for (var i = 0; i < data.length; i++) {
						record = data[i];
						var add = win.doc.createElement('option');
						add.innerHTML = record;
						add.value = record;
						attr.appendChild(add);
					}
				});
		});
	});